package com.supermap.data.service;

import com.supermap.data.dao.UserDao;
import com.supermap.data.utils.MessagePrintUtil;
import com.supermap.data.modal.TUsers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Service;

import javax.persistence.NonUniqueResultException;

@Service
public class UserService {

    @Autowired
    UserDao userDao;


    /**
     * 根据用户名和密码检查用户是否存在
     *
     * @param username
     *            用户名（登录名）
     * @param password
     *            密码
     * @return 用户对象,若未找到匹配的用户则返回null
     */
    public TUsers checkUser(String username, String password) {
        TUsers user = null;
        try {
            user = userDao.findByUserNameAndPassword(username, password);
        }catch (NonUniqueResultException ue){
            System.out.println("存在多个用户名和密码相同的用户");
        }catch (Exception e) {
            System.out.println("用户密码输入错误、或连接数据库失败!");
            e.printStackTrace();
        }
        return user;
    }



    public TUsers findByUserName(String userName){
        return userDao.findByName(userName);
    }

}
